/**
1.需要添加的组件
my_project
build
main
CMakeLists.txt
idf_component.yml   <--
main.c
CMakeLists.txt

idf_component.yml里面的内容如下
dependencies:
idf: ">=5.1"
lvgl/lvgl: ">=8.*"
esp_lvgl_port: "^1"
espressif/button: "^2"
*/
#include "driver/gpio.h"
#include "esp_lvgl_port.h"

#include "lvgl.h"

// ADC_UNIT_1
// ADC_UNIT_2
#define ADC_BUTTON_UNIT ADC_UNIT_1

// ADC_CHANNEL_0
// ADC_CHANNEL_1
// ADC_CHANNEL_2
// ADC_CHANNEL_3
// ADC_CHANNEL_4
// ADC_CHANNEL_5
// ADC_CHANNEL_6
// ADC_CHANNEL_7
// ADC_CHANNEL_8
// ADC_CHANNEL_9
#define ADC_BUTTON_CHANNEL ADC_CHANNEL_0

void adc_button_init(void)
{
    adc_oneshot_unit_handle_t adc_handle;
    adc_oneshot_unit_init_cfg_t init_config = {
        .unit_id = ADC_BUTTON_UNIT,
    };
    adc_oneshot_new_unit(&init_config, &adc_handle);

    const button_config_t lv_button_config[3] = {
        {
            .type = BUTTON_TYPE_ADC,
            .adc_button_config.adc_handle = &adc_handle,
            .adc_button_config.adc_channel = ADC_BUTTON_CHANNEL, // ADC1 channel 0 is GPIO1
            .adc_button_config.button_index = 0,
            .long_press_time = 1500,
            .short_press_time = 180,
            .adc_button_config.min = 2310, // middle is 2410mV
            .adc_button_config.max = 2510,
        },
        {
            .type = BUTTON_TYPE_ADC,
            .adc_button_config.adc_handle = &adc_handle,
            .adc_button_config.adc_channel = ADC_BUTTON_CHANNEL, // ADC1 channel 0 is GPIO1
            .adc_button_config.button_index = 1,
            .long_press_time = 1500,
            .short_press_time = 180,
            .adc_button_config.min = 1880, // middle is 1980mV
            .adc_button_config.max = 2080,
        },
        {
            .type = BUTTON_TYPE_ADC,
            .adc_button_config.adc_handle = &adc_handle,
            .adc_button_config.adc_channel = ADC_BUTTON_CHANNEL, // ADC1 channel 0 is GPIO1
            .adc_button_config.button_index = 2,
            .long_press_time = 1500,
            .short_press_time = 180,
            .adc_button_config.min = 720, // middle is 820mV
            .adc_button_config.max = 920,
        },
    };

    lv_disp_t *disp = lv_disp_get_default();
    const lvgl_port_nav_btns_cfg_t btns = {
        .disp = disp,
        .button_prev = &lv_button_config[0],
        .button_next = &lv_button_config[2],
        .button_enter = &lv_button_config[1],
    };
    lv_indev_t *indev_drv = lvgl_port_add_navigation_buttons(&btns);
    lv_group_t *g = lv_group_create();
    lv_group_set_default(g);
    lv_indev_set_group(indev_drv, g);
}